package com.htfyun.factorytest.iflytekWakeup;

import android.content.Context;
import android.text.TextUtils;

import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechUtility;
import com.iflytek.cloud.msc.util.log.DebugLog;

import com.htfyun.factorytest.R;
import com.htfyun.factorytest.utils.SystemPropertyUtil;

public class IflytekSpeechInit {
    private static String PROPERTY_DEBUG_ENABLED = "persist.wakeup.debuggable";

    public static void init(Context context) {

        DebugLog.setShowLog(isDebuggable());

        StringBuffer param = new StringBuffer();
        param.append("appid=" + context.getString(R.string.app_id));
        param.append(",");
        // 设置使用v5+
        param.append(SpeechConstant.ENGINE_MODE + "=" + SpeechConstant.MODE_MSC);
        SpeechUtility.createUtility(context, param.toString());
    }

    private static boolean isDebuggable() {
        String value = SystemPropertyUtil.getSystemProperty(PROPERTY_DEBUG_ENABLED);
        if (TextUtils.isEmpty(value)) {
            return false;
        }
        if (value.equalsIgnoreCase("true")) {
            return true;
        }
        if (value.equalsIgnoreCase("1")) {
            return true;
        }
        if (value.equalsIgnoreCase("yes")) {
            return true;
        }
        return false;
    }
}
